﻿#include "settime.h"
#include <windows.h>

bool setDateTime(QDateTime dt)
{
    SYSTEMTIME st;
    GetLocalTime(&st);//关键在这里
    st.wHour = static_cast<WORD>(dt.time().hour());
    st.wMinute = static_cast<WORD>(dt.time().minute());
    st.wSecond = static_cast<WORD>(dt.time().second());
    st.wYear = static_cast<WORD>(dt.date().year());
    st.wMonth = static_cast<WORD>(dt.date().month());
    st.wDay = static_cast<WORD>(dt.date().day());
    return SetLocalTime(&st);
}

bool setTime(QTime t)
{
    SYSTEMTIME st;
    GetLocalTime(&st);
    st.wHour = static_cast<WORD>(t.hour());
    st.wMinute = static_cast<WORD>(t.minute());
    st.wSecond = static_cast<WORD>(t.second());
    return SetLocalTime(&st);
}
